package cn.topcodes.tcsf.admin.web.websocket;

import org.springframework.web.socket.WebSocketSession;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * @author Unicorn
 * @date 2017/5/15
 */
public class WebSocketSessionCache {

    private ConcurrentMap<String,WebSocketSession> adminSessionWsMap = new ConcurrentHashMap<String, WebSocketSession>();

    public List<String> getAll() {
        return new ArrayList<>(this.adminSessionWsMap.keySet());
    }

    public void addAdminSession(String userId, WebSocketSession session) {
        adminSessionWsMap.put(userId,session);
    }

    public void removeAdminSessoin(String userId) {
        adminSessionWsMap.remove(userId);
    }

    public WebSocketSession getAdminSession(String userId) {
        return adminSessionWsMap.get(userId);
    }
}
